package form.utils
{

	/**
	 * The Value class provides formatting functions for numbers, (e.g.) percentages.
	 */	
	public class Value {
		private var _number:Number = 0;
		private var _isPercentage:Boolean = false;
		
		public function Value(num:Object, isPercentage:Boolean = false) {
			this.isPercentage = isPercentage;
			if (num is String) {
				this.number = MathUtils.forceParseFloat(String(num));
				if (String(num).match(/%\s*$/)) { this.isPercentage = true; } 
				else { this.number = Math.round(this.number); }
			} else { this.number = Number(num); }
		}
		
		public function clone():Value { return new Value(this.number, this.isPercentage); }
		
		public function get number():Number { return this._number; }
		public function set number(value:Number):void { this._number = value; }
		
		public function get isPercentage():Boolean { return this._isPercentage; }
		public function set isPercentage(value:Boolean):void { this._isPercentage = value; }
		
		public function equals(value:Value):Boolean {
			return (value != null && this.number == value.number && this.isPercentage == value.isPercentage);
		}
		
		public function toString():String { return this.number + (this.isPercentage ? "%" : ""); }
	}
}